
require 'find'

def find_regex_in_file(f, regexp)
	file = File.new f, 'r'
	lines = file.readlines
	file.close()
	count = 0
	lines.each{
		|line|
		count += 1
		line.scan(regexp){
			puts "Line:#{count}\t #{line}"
		}
	}
    
end

###########################################
def find_file(path, regex, file_name_patterns)
	regexp = Regexp.new(regex)
	file_name_regex = []
	file_name_patterns.each{
		|pattern|
		pattern = pattern.gsub(/\./, '\.')
		#p pattern
		file_name_regex << Regexp.new(pattern)
	}
	Find.find(path) do |f| 
    	if File.file?(f)
    		puts f
    		file_name_regex.each{|r|
    			find_regex_in_file(f, regexp) if f =~ r
    		}
    		
    	end
	end 

end

path, regex, *file_name_patterns = *ARGV

find_file(path, regex, file_name_patterns)

